# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-bacon
pkgver=1.2.0
_tag=1.2
pkgrel=1
pkgdesc='A small RSpec clone'
arch=(any)
url='https://github.com/leahneukirchen/bacon'
license=(MIT)
depends=(ruby)
makedepends=(ruby-rake)
options=(!emptydirs)
source=(https://github.com/leahneukirchen/bacon/archive/$pkgver/$pkgname-$_tag.tar.gz)
sha256sums=('4c16cefe2a638a181852efbe9e61321ab58269b0c8702e633ba1e74c6377033c')

prepare() {
  cd bacon-$_tag
  sed -e 's|git ls-files|find -type f|' -e 's/ ChangeLog//' -i bacon.gemspec
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd bacon-$_tag
  rake RDOX
  gem build bacon.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    bacon-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd bacon-$_tag
  GEM_HOME="tmp_install/$_gemdir" rake test
}

package() {
  cd bacon-$_tag
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 COPYING -t "$pkgdir"/usr/share/licenses/$pkgname
}
